<template>
	<view @click="openPopup">
		<view class="assistance" :style="'background-image: url(' + assistance_bg+ ')'">
			<view class="box">
				<button @click="run" :style="'background-image: url(' + btn_bg+ ')'">参与抽奖</button>
				<view class="infor">已有<text>{{all_user_num}}</text>人参与</view>
			</view>
		</view>

		<uni-popup ref="popup" type="bottom">
			<DrawSuccess :taskId="taskId" v-if="type==1" :drawitem='drawitem' @close='closePop' />
			<DrawFail v-if="type==2" @close='closePop' />
			<DrawZf v-if="type==3" @close='closePop' />
			<DrawGg v-if="type==4" :advert='advert' @close='closePop' />
			<!-- 定时抽奖 -->
			<victorydelayed v-if="type==5" :code="code" @close='closePop' />
		</uni-popup>

	</view>
</template>
<script>
	import DrawFail from '@/pagesTask/turnTable/DrawFail.vue';
	import DrawSuccess from '@/pagesTask/turnTable/DrawSuccess.vue';
	import DrawGg from '@/pagesTask/turnTable/DrawGg.vue';
	import DrawZf from '@/pagesTask/turnTable/DrawZf.vue';
	import victorydelayed from '@/pagesTask/turnTable/VictoryDelayed.vue';
	export default {
		components: {
			DrawFail,
			DrawSuccess,
			DrawGg,
			DrawZf,
			victorydelayed
		},
		data() {
			return {
				domain: uni.$http.baseUrl + "/",
				assistance_bg: `${uni.imgPath}/upload/h5/lucky/2.png`,
				btn_bg: `${uni.imgPath}/upload/turnbg/btn_part.png`,
				type: 0,
				index: 0,
				all_user_num: 0,
				advert: {},

			}
		},
		props: {
			taskId: {
				type: String,
				default: ""
			},
			help: {
				type: Object,
				default: () => ({})
			}
		},
		mounted() {
			this.getNum();
		},
		methods: {
			getNum() {
				uni.$http.post('/wxuser/index/getNum', {
					id: this.taskId
				}).then(res => {
					var data = res.data.data;
					this.all_user_num = data.all_user_num;

				})
			},
			run() {

				uni.$http.post('/wxuser/draw/run', {
					id: this.taskId
				}).then(res => {
					if (res.data.code == 0) {
						uni.showToast({
							icon: "error",
							title: res.data.msg,
							duration: 2000
						})
						this.$refs.popup.close()
						return
					}
					var data = res.data.data;
					this.index = 0;
					if (data.type) {
						this.type = data.type
						this.advert = data.advert

					} else {
						if (data.list) {
							if (data.list.code) {
								this.type = 5
								this.code = data.list.code
							} else {
								this.type = 1 //中奖了
								if (data.list.level || data.list.level == 0) {
									this.index = data.list.level
								} else {
									this.index = this.prizes.length - 1
								}
							}

							this.drawitem = data.list
						} else {
							this.type = 2;

						}

					}
					if (this.type != 0) {
						this.openPopup()
					}
				})
			},
			close() {
				this.$refs.popup.close()
			},
			openPopup() {
				this.$refs.popup.open()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.assistance {
		position: relative;
		margin: 30rpx;
		background-size: 100% 100%;
		height: 700rpx;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;

		.box {
			color: #000;

			.infor {
				text-align: center;
				margin-top: 16rpx;
			}
		}

		button {
			background-size: 100% 100%;
			color: #DE0000;
			font-size: 40rpx;
			width: 300rpx;
			margin: 0;
			height: 75rpx;
			text-align: center;
			line-height: 75rpx;
			border-radius: 30rpx;
			background-color: rgba(0, 0, 0, 0);
			// position: absolute;
			// top: 50%;
			// left: 50%;
			// transform: translateX(-50%);
		}


	}
</style>